#include "widget.h"
#include "ui_widget.h"
#include<QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //了解textEdit的相关信号
    //1. 编写内容时, textChanged 和 cursorPositionChanged 会触发
    //2.选中⼀段⽂本时, cursorPositionChanged , selectionChanged , copyAvailable会触发
    //3.按下 ctrl + z 时, textChanged , undoAvailable , redoAvailable ,cursorPositionChanged 会触发
    //4.按下 ctrl + y, textChanged , undoAvailable , redoAvailable ,cursorPositionChanged 会触发
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_textEdit_copyAvailable(bool b)
{
    qDebug() << "[copyAvailable] " << b;
}


void Widget::on_textEdit_currentCharFormatChanged(const QTextCharFormat &format)
{
    qDebug() << "[on_textEdit_currentCharFormatChanged] ";
}


void Widget::on_textEdit_cursorPositionChanged()
{
    const QTextCursor& cursor = ui->textEdit->textCursor();
    qDebug() << "[cursorPositionChanged] " << cursor.position();
}


void Widget::on_textEdit_redoAvailable(bool b)
{
    qDebug() << "[redoAvailable] " << b;
}


void Widget::on_textEdit_selectionChanged()
{
    const QTextCursor& cursor = ui->textEdit->textCursor();
    qDebug() << "[selectionChanged] " << cursor.selectedText();
}


void Widget::on_textEdit_undoAvailable(bool b)
{
    qDebug() << "[undoAvailable] " << b;
}


void Widget::on_textEdit_textChanged()
{
    qDebug() << "[textChanged] " << ui->textEdit->toPlainText();
}

